<template>
<view class="uni-padding-wrap uni-common-mt" style="height: 100vh;
    margin-top: 50%;
    margin-left: 15%;">
	       <view style="font-size: 1.3rem;">店铺名称：{{deptName}}</view>
			<view class="uni-title" style="font-size: 1.3rem;">是否闭店:  &nbsp;&nbsp;<switch style="margin-left: 2rem;" :checked="isCheck"  @change="changeShopstatus" /></view>
			<view>
				
			</view>
		
		</view>
</template>

<script>
export default {
	data(){
		return {
			isCheck:false,
			deptName: uni.getStorageSync("deptName")
		}
	},
	mounted(){
		uni.showLoading({
		    title: '加载中...'
		});
		this.$api.ajax({
		    url: "/web/trDept/admin/getSysZzjgById",
		    header: {
		      "Authorization": "Bearer "+uni.getStorageSync("jwttoken")
		    },
		
		    data: {
				id: uni.getStorageSync("deptId")
		    },
		    success: (res) => {
				const { data } = res.data || {};
				const { items } = data || {};
				if(data == null && res.data.status == 403
				||res.data.code == 401) {
				    uni.navigateTo({
				        url: '/pages/login/login'
				    })
				    return
				}
		        // 成功
		        console.log("状态",res.data.data.isClose)
				this.isCheck = res.data.data.isClose
		    },
		    fail: (res) => {
		        this.$api.msg("开了小差");
		    },
		    complete: (res) => {
		        uni.hideLoading();
		    }
		});	
	},
	methods:{
		changeShopstatus(e){
			let isclose = e.detail.value?1:0
			console.log("当前用户zzjgid",uni.getStorageSync("deptId"))
			uni.showLoading({
			    title: '加载中...'
			});
			this.$api.ajax({
			    url: "/web/trDept/admin/editDepartment",
			    method: "post",
			    header: {
			        "Content-Type": "application/json",
			      "Authorization": "Bearer "+uni.getStorageSync("jwttoken")
			    },
			
			    data: {
			        isClose: isclose,
					id: uni.getStorageSync("deptId")
			    },
			    success: (res) => {
			        // 成功
			        this.$api.msg("成功");
			    
			    },
			    fail: (res) => {
			        this.$api.msg("开了小差");
			    },
			    complete: (res) => {
			        uni.hideLoading();
			    }
			});	
		}
	}
}
</script>

<style  lang="scss">
	.btn{
		font-size: 50rpx;
		border-radius: 20rpx;
		margin: 0;
		//background: linear-gradient(to right, rgb(58 132 64 / 70%), rgb(116 177 112));
		background:linear-gradient(to right, rgba(58,132,64,0.7), rgba(116,177,112,0.6));
		margin-bottom: 25rpx;

	}
	.container{
		width: 70%;
		margin: -80rpx auto;
		display: flex;
		flex-direction:column;
		justify-content: center;
	}

</style>